function Build() {
	var me = this;
	var data;
	
	me.data = {
		name : 'New Build',
		
		/*
		 * 0 : Knight
		 * 1 : Warrior
		 * 2 : Monk
		 * 3 : Beastmaster
		 */
		
		classId : null,
		class : null,
		
		/* Base Stats */
		
		baseStats : {
			hp : 0,
			defenseRate : 20,
			dodgeRate : 0,
			parryRate : 0
		},
		
		/* Group Buffs */
		
		groupBuffs : {
			
		},
		
		eh : {
			base : 0,
			selfBuffed : 0,
			groupBuffed : 0
		},
		
		ehDP : {
			base : 0,
			selfBuffed : 0,
			groupBuffed : 0
		}
	};
	
	me.Events = {
		'ehchanged' : [],
		'changed' : [],
		'namechanged' : [],
		'classchanged' : [],
		'hpchanged' : [],
		'defenseratechanged' : [],
		'dodgeratechanged' : [],
		'parryratechanged' : [],
		'selfbuffchanged' : [],
		'groupbuffchanged' : []
	};
	
	me.initInternalListeners();
}

Build.prototype = new Event();

Build.prototype.init = function(data) {
	
};

Build.prototype.initInternalListeners = function() {
	
	var me = this;
	
	me.on('classchanged, hpchanged, defenseratechanged, selfbuffchanged, groupbuffchanged', function() {
		me.refreshEh();
	});
	
	me.on('classchanged, dodgeratechanged, defenseratechanged, selfbuffchanged, groupbuffchanged', function() {
		me.refreshEhDP();
	});
};

Build.prototype.refreshEh = function() {
	var me = this;

	var totalHp = (me.Hp + me.Class.getModifier('hp', 'add')) * me.Class.getModifier('hp', 'mult');
	var totalDefenseRate = (me.DefenseRate + me.Class.getModifier('defenseRate', 'add')) * me.Class.getModifier('defenseRate', 'mult');
	
	me.data.eh.base = me.Hp * (1.0 + me.DefenseRate / 100.0);
	me.data.eh.selfBuffed = totalHp * (1.0 + totalDefenseRate / 100.0);
	
	console.log(me.data.eh);
	
	me.broadcast('ehchanged');
};

Build.prototype.refreshEhDP = function() {
	
};

Object.defineProperty(Build.prototype, "Name", {
	get : function() {
		return this.data.name;
	},
	set : function(value) {
		if (value != undefined && value != '') {
			this.data.name = value;
			this.broadcast('namechanged');
		}
	}
});

Object.defineProperty(Build.prototype, "ClassId", {
	get : function() {
		return this.data.classId;
	},
	set : function(value) {
		var me = this;
		
		if (value != undefined && value !== '') {
			this.data.classId = parseInt(value); // TODO check que c'est bien un int, la flemme là
			
			switch (this.data.classId) {
			case 0:
				this.data.class = new Knight();
				break;
			}
			
			for (var i = 0; i < this.Class.Buffs.length; i++) {
				this.Class.Buffs[i].on('levelchanged', function() {
					me.broadcast('selfbuffchanged');
				});
			}
			
			this.broadcast('classchanged');
		}
	}
});

Object.defineProperty(Build.prototype, "Class", {
	get : function() {
		return this.data.class;
	}
});

Object.defineProperty(Build.prototype, "Hp", {
	get : function() {
		return this.data.baseStats.hp;
	},
	set : function(value) {
		if (value != undefined && value != '') {
			var value = parseInt(value);
			if (value != NaN) {
				this.data.baseStats.hp = value;
				this.broadcast('hpchanged');
			}
		}
	}
});

Object.defineProperty(Build.prototype, "DefenseRate", {
	get : function() {
		return this.data.baseStats.defenseRate;
	},
	set : function(value) {
		if (value != undefined && value != '') {
			var value = parseFloat(value);
			if (value != NaN) {
				this.data.baseStats.defenseRate = value;
				this.broadcast('defenseratechanged');
			}
		}
	}
});

Object.defineProperty(Build.prototype, "DodgeRate", {
	get : function() {
		return this.data.baseStats.dodgeRate;
	},
	set : function(value) {
		if (value != undefined && value != '') {
			var value = parseFloat(value);
			if (value != NaN) {
				this.data.baseStats.dodgeRate = value;
				this.broadcast('dodgeratechanged');
			}
		}
	}
});

Object.defineProperty(Build.prototype, "ParryRate", {
	get : function() {
		return this.data.baseStats.parryRate;
	},
	set : function(value) {
		if (value != undefined && value != '') {
			var value = parseFloat(value);
			if (value != NaN) {
				this.data.baseStats.parryRate = value;
				this.broadcast('parryratechanged');
			}
		}
	}
});


Object.defineProperty(Build.prototype, "SelfBuffs", {
	get : function() {
		return this.data.selfBuffs;
	}
});
